Get DBE list form DB

Is it possible to get a list of child DBEs from a DB variable? This is so they can be read from callback functions with a DB argument when not declared globally.
SystemAdmin - Wed Dec 22 11:05:56 EST 2010

Re: Get DBE list form DB
llandale - Wed Dec 22 16:11:15 EST 2010

Not directly, but you could define a global Skip list and put the DBEs therein after you create them.

Seems like an odd requirement, not had trouble defining them globally.

Re: Get DBE list form DB
SystemAdmin - Thu Dec 23 06:41:45 EST 2010

llandale - Wed Dec 22 16:11:15 EST 2010
Not directly, but you could define a global Skip list and put the DBEs therein after you create them.

Seems like an odd requirement, not had trouble defining them globally.

Yeah globals are fine until you start writing more complex stuff where I'd rather use variables contained in function scope. Just makes the code easier to maintain. DBs are one of the main things that require globals which is a pain if you invoke multiple instances of a DB.
Wondered if there was a way to do clever things with addr_ to 'attach' a property to a DB.
I've used addr_ to 'pass' a DBE to a callback by setting and getting the DB Title but that gives the DB an ugly title.

Re: Get DBE list form DB
Mathias Mamsch - Sat Jan 08 12:50:11 EST 2011

SystemAdmin - Thu Dec 23 06:41:45 EST 2010
Yeah globals are fine until you start writing more complex stuff where I'd rather use variables contained in function scope. Just makes the code easier to maintain. DBs are one of the main things that require globals which is a pain if you invoke multiple instances of a DB.
Wondered if there was a way to do clever things with addr_ to 'attach' a property to a DB.
I've used addr_ to 'pass' a DBE to a callback by setting and getting the DB Title but that gives the DB an ugly title.

In fact you can do a dialog "class" which defines properties to your handles. You can even do callback-properties, where the user program can supply a custom function that shall be called, when the user does something in a dialog. If you are interested, I can extend the example (below).

Hope that helps, regards, Mathias
 

struct MyDialog {}
DxlObject DxlObjectOf (MyDialog D) { return (addr_ D) DxlObject }
 
DB get_DBHandle (MyDialog D) { return ((DxlObjectOf D)->"DBHandle") DB}
void set_DBHandle (MyDialog D, DB var) { (DxlObjectOf D)->"DBHandle" = var}
 
// Define the controls here
 
DBE get_Text (MyDialog D) { return ((DxlObjectOf D)->"TextField") DBE }
void set_Text (MyDialog D, DBE var) { (DxlObjectOf D)->"TextField" = var}
 
DBE get_Label (MyDialog D) { return ((DxlObjectOf D)->"Label") DBE }
void set_Label (MyDialog D, DBE var) { (DxlObjectOf D)->"Label" = var}
 
// .. repeat that for as many controls as you want ...
 
MyDialog createMyDialog_ () { DxlObject x = new(); return (addr_ x) MyDialog }
 
MyDialog BuildDialog (string title) {
       MyDialog result = createMyDialog_(); 
       
       DB diag = create title
       set_DBHandle (result, diag) 
 
       DBE lab = label (diag, "My Label") 
       set_Label (result, lab) 
 
       DBE txt = field (diag, "Text", "", 40) 
       set_Text (result, txt)
 
       return result
}
 
MyDialog diagA = BuildDialog "Hallo"
MyDialog diagB = BuildDialog "You" 
 
realize get_DBHandle diagA
realize get_DBHandle diagB
 
set (get_Text diagA, "Text for Dialog A") 
set (get_Text diagB, "Text for Dialog B")

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Get DBE list form DB
SystemAdmin - Mon Jan 10 07:45:56 EST 2011

Mathias Mamsch - Sat Jan 08 12:50:11 EST 2011

In fact you can do a dialog "class" which defines properties to your handles. You can even do callback-properties, where the user program can supply a custom function that shall be called, when the user does something in a dialog. If you are interested, I can extend the example (below).

Hope that helps, regards, Mathias
 

struct MyDialog {}
DxlObject DxlObjectOf (MyDialog D) { return (addr_ D) DxlObject }
 
DB get_DBHandle (MyDialog D) { return ((DxlObjectOf D)->"DBHandle") DB}
void set_DBHandle (MyDialog D, DB var) { (DxlObjectOf D)->"DBHandle" = var}
 
// Define the controls here
 
DBE get_Text (MyDialog D) { return ((DxlObjectOf D)->"TextField") DBE }
void set_Text (MyDialog D, DBE var) { (DxlObjectOf D)->"TextField" = var}
 
DBE get_Label (MyDialog D) { return ((DxlObjectOf D)->"Label") DBE }
void set_Label (MyDialog D, DBE var) { (DxlObjectOf D)->"Label" = var}
 
// .. repeat that for as many controls as you want ...
 
MyDialog createMyDialog_ () { DxlObject x = new(); return (addr_ x) MyDialog }
 
MyDialog BuildDialog (string title) {
       MyDialog result = createMyDialog_(); 
       
       DB diag = create title
       set_DBHandle (result, diag) 
 
       DBE lab = label (diag, "My Label") 
       set_Label (result, lab) 
 
       DBE txt = field (diag, "Text", "", 40) 
       set_Text (result, txt)
 
       return result
}
 
MyDialog diagA = BuildDialog "Hallo"
MyDialog diagB = BuildDialog "You" 
 
realize get_DBHandle diagA
realize get_DBHandle diagB
 
set (get_Text diagA, "Text for Dialog A") 
set (get_Text diagB, "Text for Dialog B")

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Thanks for the example. I understand what you are doing but don't see how it can be used to get DBE data when in a callback if the DBE is not Global.

void ApplyButtonCallback(DB win)
{
string TextField = ""
//get (get_Text diagA) // But we only have 'win' not diagA
infoBox("This is the text in the Text Filed of whichever DB we are in:\n" TextField)
}

Re: Get DBE list form DB
SystemAdmin - Mon Jan 10 08:03:25 EST 2011

SystemAdmin - Mon Jan 10 07:45:56 EST 2011
Thanks for the example. I understand what you are doing but don't see how it can be used to get DBE data when in a callback if the DBE is not Global.

void ApplyButtonCallback(DB win)
{
string TextField = ""
//get (get_Text diagA) // But we only have 'win' not diagA
infoBox("This is the text in the Text Filed of whichever DB we are in:\n" TextField)
}

This is the sort of thing I had been playing with. It works but has the addr_ number as a title whick is not too nice.
 

/******************************************* ReportMessageBox ******************************************
Function Name:    ReportMessageBox
Description:            Displays a message box which can display a large message.
                                                                If necessary a scroll bar is displayed.
Parameters:                     TitleString - Title for Dialog Box
                                                                LabelString - Label of Text Message
                                                                MessageString - Message for Dialog Box
                                                                ConfirmButton - Confirm, Cancel Buttons rather than an OK Button
Result:                                 Returns true unless Cancel is pressed.
*******************************************************************************************************/
 
bool ReportMessageBox(string TitleString, string LabelString, string MessageString, bool ConfirmButton)
{
        bool Confirmed = true
        DB ReportDB = create(TitleString, styleCentered|styleFloating)
 
        Skip ListDBE = createString
        setTitle(ReportDB, ((addr_(ListDBE)) int) "")
 
                if(LabelString != "")
                {
                        label(ReportDB, LabelString)
                }
 
                if(MessageString != "")
                {
                        text(ReportDB, "", MessageString, 200, true)
                }
 
                        void getCoffees(DBE CoffeeList)
                        {
                    int i = get CoffeeList
                    string s = get CoffeeList
 
//                              DB PassedDB = getParent(CoffeeList)
//                              setTitle(PassedDB, s)
 
                    if (i == 0) ack "Mmm, Mocha..."
                    if (i == 4) ack "Watch out for trademark violations"
                        }
 
                        void TestButtonClickCallback(DB PassedDB)
                        {
                                // Get the List BDE
                                string DBTitle = getTitle(PassedDB)
                                int Address = intOf(DBTitle)
                                Skip ListDBE = (addr_ Address) Skip
                                DBE aDBE
 
                                // Get the List
                                find(ListDBE, "CoffeeListDBE", aDBE)
 
                                // Read the Value
                          int i = get aDBE
                          string s = get aDBE
 
 
                                print i ": " s "\n"
                        }
 
                        void OKButtonClickCallback(DB PassedDB)
                        {
                                // Use the DB Title to get data out
                                setTitle(PassedDB, "True")
                                release(PassedDB)
                        }
 
                        void CancelButtonClickCallback(DB PassedDB)
                        {
                                // Use the DB Title to get data out
                                setTitle(PassedDB, "False")
                                release(PassedDB)
                        }
 
                // List
                string coffees[] = {"Mocha", "Sumatra Blue", "Mysore", "Kenya", "Java"}
                DBE CoffeeListDBE = list(ReportDB, "Choose one of:", 4, coffees)
                put(ListDBE, "CoffeeListDBE", CoffeeListDBE)
 
                // run callback directly upon list selection
                set(CoffeeListDBE, getCoffees)
 
                apply(ReportDB, "Test", TestButtonClickCallback)
 
                if(ConfirmButton)
                {
                        ok(ReportDB, "Confirm", OKButtonClickCallback)
                        ok(ReportDB, "Cancel", CancelButtonClickCallback)
                }
                else
                {
                        ok(ReportDB, "OK", OKButtonClickCallback)
                }
 
                // Hide Close Button
                close(ReportDB, false, CancelButtonClickCallback)
 
                realize(ReportDB)                       // Realize Dialogue Box in Memory - not yet visible
                raise(ReportDB)                         // Ensures Dialogue Box appears infront of all other windows
                block(ReportDB)                         // Show Dialog Box and freezes DOORS user interface - user can only react with DB.
 
        // Execution Paused & Resumes Here After A Callback or "release(ReportDB)"
 
        string DBTitle = getTitle(ReportDB)
        if(DBTitle == "False")
        {
                Confirmed = false
        }
 
        delete ListDBE
        release(ReportDB)                               // Releases Memory back to OS.
        destroy(ReportDB)
        ReportDB = null
 
        return Confirmed
}
/**************************************** END ReportMessageBox ****************************************/
 
infoBox ReportMessageBox("TitleString", "Caption Text", "Message Text", true) ""

Re: Get DBE list form DB
Mathias Mamsch - Mon Jan 10 10:00:44 EST 2011

SystemAdmin - Mon Jan 10 07:45:56 EST 2011
Thanks for the example. I understand what you are doing but don't see how it can be used to get DBE data when in a callback if the DBE is not Global.

void ApplyButtonCallback(DB win)
{
string TextField = ""
//get (get_Text diagA) // But we only have 'win' not diagA
infoBox("This is the text in the Text Filed of whichever DB we are in:\n" TextField)
}

Ok, I thought you were asking about having a dialog, without declaring the elements as global variables. So why would it be bad to have one global Skip list, which maps Dialogs (DB) to MyDialog or DBE text fields (your modified code, see below)? If you used the struct{} approach, you could just map the dialog handle (DB) to the MyDialog and then you could have as many dialog instances open as you want, access all DBEs in the dialog from all callbacks.

Or is this about avoiding ALL global variables for Copy/Paste reasons or even including the same file twice?

Regards, Mathias
 

Skip gl_Button_to_List = create() 
 
bool ReportMessageBox(string TitleString, string LabelString, string MessageString, bool ConfirmButton)
{
    bool Confirmed = true
        DB ReportDB = create(TitleString, styleCentered|styleFloating)
 
        setTitle(ReportDB, TitleString)
 
        if(LabelString != "") { label(ReportDB, LabelString) }
        if(MessageString != "")       { text(ReportDB, "", MessageString, 200, true)      }
 
        void getCoffees(DBE CoffeeList) {
                int i = get CoffeeList
                string s = get CoffeeList
 
                if (i == 0) ack "Mmm, Mocha..."
                if (i == 4) ack "Watch out for trademark violations"
        }
 
        void TestButtonClickCallback(DB PassedDB) {
                DBE aDBE
 
                find(gl_Button_to_List, PassedDB, aDBE)
 
                int i = get aDBE
                string s = get aDBE
                print i ": " s "\n"
        }
 
        void OKButtonClickCallback(DB PassedDB) {
                // Use the DB Title to get data out
                setTitle(PassedDB, "True")
                release(PassedDB)
        }
 
        void CancelButtonClickCallback(DB PassedDB) {
                // Use the DB Title to get data out
                setTitle(PassedDB, "False")
                release(PassedDB)
        }
 
        // List
        string coffees[] = {"Mocha", "Sumatra Blue", "Mysore", "Kenya", "Java"}
        DBE CoffeeListDBE = list(ReportDB, "Choose one of:", 4, coffees)
 
        // run callback directly upon list selection
        set(CoffeeListDBE, getCoffees)
 
        apply(ReportDB, "Test", TestButtonClickCallback)
        put(gl_Button_to_List, ReportDB, CoffeeListDBE)
 
        if(ConfirmButton) {
                ok(ReportDB, "Confirm", OKButtonClickCallback)
                ok(ReportDB, "Cancel", CancelButtonClickCallback)
        } else {
                ok(ReportDB, "OK", OKButtonClickCallback)
        }
 
        // Hide Close Button
        close(ReportDB, false, CancelButtonClickCallback)
 
        realize(ReportDB)                       // Realize Dialogue Box in Memory - not yet visible
        raise(ReportDB)                         // Ensures Dialogue Box appears infront of all other windows
        block(ReportDB)                         // Show Dialog Box and freezes DOORS user interface - user can only react with DB.
 
        // Execution Paused & Resumes Here After A Callback or "release(ReportDB)"
 
        string DBTitle = getTitle(ReportDB)
        if(DBTitle == "False")
        {
                Confirmed = false
        }
 
        release(ReportDB)                               // Releases Memory back to OS.
        destroy(ReportDB)
        ReportDB = null
 
        return Confirmed
}
/**************************************** END ReportMessageBox ****************************************/
 
infoBox ReportMessageBox("TitleString", "Caption Text", "Message Text", true) ""

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Get DBE list form DB
SystemAdmin - Tue Jan 11 07:59:10 EST 2011

Mathias Mamsch - Mon Jan 10 10:00:44 EST 2011

Ok, I thought you were asking about having a dialog, without declaring the elements as global variables. So why would it be bad to have one global Skip list, which maps Dialogs (DB) to MyDialog or DBE text fields (your modified code, see below)? If you used the struct{} approach, you could just map the dialog handle (DB) to the MyDialog and then you could have as many dialog instances open as you want, access all DBEs in the dialog from all callbacks.

Or is this about avoiding ALL global variables for Copy/Paste reasons or even including the same file twice?

Regards, Mathias
 

Skip gl_Button_to_List = create() 
 
bool ReportMessageBox(string TitleString, string LabelString, string MessageString, bool ConfirmButton)
{
    bool Confirmed = true
        DB ReportDB = create(TitleString, styleCentered|styleFloating)
 
        setTitle(ReportDB, TitleString)
 
        if(LabelString != "") { label(ReportDB, LabelString) }
        if(MessageString != "")       { text(ReportDB, "", MessageString, 200, true)      }
 
        void getCoffees(DBE CoffeeList) {
                int i = get CoffeeList
                string s = get CoffeeList
 
                if (i == 0) ack "Mmm, Mocha..."
                if (i == 4) ack "Watch out for trademark violations"
        }
 
        void TestButtonClickCallback(DB PassedDB) {
                DBE aDBE
 
                find(gl_Button_to_List, PassedDB, aDBE)
 
                int i = get aDBE
                string s = get aDBE
                print i ": " s "\n"
        }
 
        void OKButtonClickCallback(DB PassedDB) {
                // Use the DB Title to get data out
                setTitle(PassedDB, "True")
                release(PassedDB)
        }
 
        void CancelButtonClickCallback(DB PassedDB) {
                // Use the DB Title to get data out
                setTitle(PassedDB, "False")
                release(PassedDB)
        }
 
        // List
        string coffees[] = {"Mocha", "Sumatra Blue", "Mysore", "Kenya", "Java"}
        DBE CoffeeListDBE = list(ReportDB, "Choose one of:", 4, coffees)
 
        // run callback directly upon list selection
        set(CoffeeListDBE, getCoffees)
 
        apply(ReportDB, "Test", TestButtonClickCallback)
        put(gl_Button_to_List, ReportDB, CoffeeListDBE)
 
        if(ConfirmButton) {
                ok(ReportDB, "Confirm", OKButtonClickCallback)
                ok(ReportDB, "Cancel", CancelButtonClickCallback)
        } else {
                ok(ReportDB, "OK", OKButtonClickCallback)
        }
 
        // Hide Close Button
        close(ReportDB, false, CancelButtonClickCallback)
 
        realize(ReportDB)                       // Realize Dialogue Box in Memory - not yet visible
        raise(ReportDB)                         // Ensures Dialogue Box appears infront of all other windows
        block(ReportDB)                         // Show Dialog Box and freezes DOORS user interface - user can only react with DB.
 
        // Execution Paused & Resumes Here After A Callback or "release(ReportDB)"
 
        string DBTitle = getTitle(ReportDB)
        if(DBTitle == "False")
        {
                Confirmed = false
        }
 
        release(ReportDB)                               // Releases Memory back to OS.
        destroy(ReportDB)
        ReportDB = null
 
        return Confirmed
}
/**************************************** END ReportMessageBox ****************************************/
 
infoBox ReportMessageBox("TitleString", "Caption Text", "Message Text", true) ""

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Well, I was hoping it could be done without any globals so the function would have no dependancies but I guess globals just can't be avoided when dealing with Dbs. The global skip and custom struct is close though. cheers